package com.lcu.student.controller;

import com.lcu.Result.Result;
import com.lcu.student.entity.StudentGrades;
import com.lcu.student.service.StudentGradesService;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/grades")
public class StudentGradesController {

    @Autowired
    private StudentGradesService service;

    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/getPageAll/{currentPage}/{pageSize}")
    public Result getPageAll(@PathVariable("currentPage") int currentPage, @PathVariable("pageSize") int pageSize){
        return service.selectByPage(currentPage,pageSize);
    }

    /**
     * 带条件的分页查询
     * @param currentPage
     * @param pageSize
     * @return
     */
    @PostMapping("/getPageAll2/{currentPage}/{pageSize}")
    public Result getPageAll2(@PathVariable("currentPage") int currentPage, @PathVariable("pageSize") int pageSize,@RequestBody StudentGrades studentGrades){
        return service.selectByPage2(currentPage,pageSize,studentGrades);
    }

    /**
     * 查询学生姓名
     * @return
     */
    @GetMapping("/selectStudent")
    public Result selectStudent(){
        return service.selectStudent();
    }

    /**
     * 根据姓名查询学号
     * @param studentName
     * @return
     */
    @GetMapping("/selectStudentNumber/{studentName}")
    public Result selectStudentNumber(@PathVariable String studentName){
        return service.selectStudentNumber(studentName);
    }

    /**
     * 添加学生成绩数据
     * @param studentGrades
     * @return
     */
    @PostMapping("/addGrades")
    public Result addGrades(@RequestBody StudentGrades studentGrades){
        return service.addGrades(studentGrades);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable int id){
        return service.deleteById(id);
    }

    /**
     * 批量删除数据
     * @param selectedIds
     * @return
     */
    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> selectedIds){
        return service.deleteByIds(selectedIds);
    }

    /**
     * 根据id修改
     * @param studentGrades
     * @return
     */
    @PutMapping("/updateById")
    public Result updateById(@RequestBody StudentGrades studentGrades){
        return service.updateById(studentGrades);
    }

    /**
     * 查询所有科目
     * @return
     */
    @GetMapping("/selectSubjects")
    public Result selectSubjects(){
        return service.selectSubjects();
    }

    /**
     * 根据科目查询平均分
     * @return
     */
    @PostMapping("/selectScores")
    public Result selectScores(){
        return service.selectScores();
    }

    /**
     * 根据科目查询及格人数
     * @return
     */
    @GetMapping("/selectPass")
    public Result selectPass(){
        return service.selectPass();
    }

}
